﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Practices.EnterpriseLibrary.Data;
using System.Data;
using System.Data.Common;

namespace MINERP.DAL.FactoryTech
{
    public class FactoryTechDAL
    {
        /// <summary>
        /// 获取打印信息
        /// </summary>
        /// <param name="inproductId"></param>
        /// <returns></returns>
        public DataTable GetPrintInfo(string inproductId)
        {

            Database db = null;

            DataSet dsPrint = null;
            try
            {
                db = DatabaseFactory.CreateDatabase();

                //string sqlCommand = "select OrderProductName,CtmName,OrderProductCode,shopName,sum(photoinfo.totalNum) PageNum,FetchTime from orderInfo,Tb_OrderBag,Shop,photoinfo where orderInfo.OrderBagId=Tb_OrderBag.OrderBagId and  Tb_OrderBag.shopID=Shop.ShopId and orderInfo.ParentProductId=0  and orderInfo.orderproductid =photoInfo.orderproductid and  orderInfo.OrderProductCode='" + inproductId + "' group by OrderProductName,CtmName,OrderProductCode,shopName,PageNum,FetchTime";

                StringBuilder sqlBuilder = new StringBuilder();
                sqlBuilder.Append(" select OrderProductName,CtmName,OrderProductCode,shopName, isnull(sum(photoinfo.totalNum),0) PageNum,FetchTime ");
                sqlBuilder.Append(" from orderInfo  inner join Tb_OrderBag on orderInfo.OrderBagId=Tb_OrderBag.OrderBagId ");
                sqlBuilder.Append(" inner  join Shop on Tb_OrderBag.shopID=Shop.ShopId ");
                sqlBuilder.Append(" left join  photoinfo on  orderInfo.orderproductid =photoInfo.orderproductid ");
                sqlBuilder.Append(" where  orderInfo.OrderProductCode='" + inproductId + "' ");
                sqlBuilder.Append(" group by OrderProductName,CtmName,OrderProductCode,shopName,PageNum,FetchTime");
                DbCommand dbCommand = db.GetSqlStringCommand(sqlBuilder.ToString());
                dsPrint = db.ExecuteDataSet(dbCommand);

            }
            catch
            {

            }
            if (dsPrint == null)
            {
                return null;
            }
            else
            {
                return dsPrint.Tables[0];
            }
        }
    }
}
